
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class AddCustomerPage(BasePage):
    url = "/crm/index.php?m=customer&a=add"
    result_locator = (By.XPATH, '/html/body/div[5]/div[2]')
    error_locator =(By.XPATH,"/html/body/div/form/fieldset/div[1]")
    owner_name_locator = (By.ID, 'owner_name')  # 负责人
    d_name_locator = (By.ID, 'd_name')  # 选择负责人搜索框
    search_button_locator = (By.XPATH, '//*[@id="dialog-role-list"]/div/ul/button')  # 选择负责人搜索按钮
    choose_locator = (By.XPATH, '//*[@id="d_content"]/tr/td[1]/input')  # 选择负责人
    ok_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]')  # ok键
    name_locator = (By.ID, 'name')  # 客户名称
    industry_locator = (By.ID, 'industry')  # 客户行业
    origin_locator = (By.ID, 'origin')  # 客户信息来源
    ownership_locator = (By.ID, 'ownership2')  # 公司性质
    zip_code_locator = (By.ID, 'zip_code')  # 邮编
    annual_revenue_locator = (By.ID, 'annual_revenue')  # 年营业额
    rating_locator = (By.ID, 'rating1')  # 评分
    state_locator = (By.NAME, "address['state']")  # 客户联系地址 ：省
    city_locator = (By.NAME, "address['city']")  # 客户联系地址 ：市
    area_locator = (By.NAME, "address['area']")  # 客户联系地址 ：区
    street_locator = (By.NAME, "address['street']")  # 客户联系地址 :街道
    first_name_locator = (By.XPATH, '//*[@id="form1"]/table/tbody/tr[8]/td[2]/input')  # 姓名
    salt_name_locator = (By.NAME, 'saltname')  # 称呼
    con_email_locator = (By.NAME, 'con_email')  # 邮箱
    con_post_locator = (By.NAME, 'con_post')  # 职位
    con_qq_locator = (By.NAME, 'con_qq')  # QQ
    con_telephone_locator = (By.NAME, 'con_telephone')  # 手机
    con_description_locator = (By.NAME, 'con_description')  # 备注
    no_of_employees_locator = (By.ID, 'no_of_employees')  # 员工数
    description_locator = (By.ID, 'description')  # 备注
    save_locator = (By.XPATH, '//*[@id="form1"]/table/tfoot/tr/td/input[1]')  # 保存
    tips_locator = (By.CSS_SELECTOR, 'body > div.container > div.alert.alert-success')
    del_choose_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    batch_del_locator = (By.CSS_SELECTOR, 'body > div.container > div.row > div:nth-child(1) > ul > div > a')

    def click_owner_name(self):
        """
        点击负责人选框
        """
        self.find_element(self.owner_name_locator).click()

    def input_d_name(self, d_name):
        """
        输入搜索负责人关键词
        """
        self.find_element(self.d_name_locator).send_keys(d_name)

    def click_search_btn(self):
        """
        点击搜索按钮
        """
        self.find_element(self.search_button_locator).click()

    def click_choose_owner(self):
        """
        点击选择负责人
        """
        self.find_element(self.choose_locator).click()

    def click_ok_btn(self):
        """
        点击ok键
        """
        self.find_element(self.ok_locator).click()

    def input_customer_name(self, customer_name):
        """
        输入客户名称
        """
        self.find_element(self.name_locator).send_keys(customer_name)

    def select_industry(self, industry_value):
        """
        选择客户行业
        """
        industry_element = Select(self.find_element(self.industry_locator))
        industry_element.select_by_value(industry_value)

    def select_origin(self, origin_value):
        """
        选择客户信息来源
        """
        origin_element = Select(self.find_element(self.origin_locator))
        origin_element.select_by_value(origin_value)

    def click_ownership(self):
        """
        点击选择的公司性质
        """
        self.find_element(self.ownership_locator).click()

    def input_zip_code(self, zip_code):
        """
        选择年营业额
        """
        self.find_element(self.zip_code_locator).send_keys(zip_code)

    def select_annual_revenue(self, annual_revenue_value):
        """
        选择年营业额
        """
        annual_revenue_element = Select(self.find_element(self.annual_revenue_locator))
        annual_revenue_element.select_by_value(annual_revenue_value)

    def click_rating(self):
        """
        点击选择评分
        """
        self.find_element(self.rating_locator).click()

    def select_state(self, state_value):
        """
        客户联系地址选择省
        """
        state_element = Select(self.find_element(self.state_locator))
        state_element.select_by_value(state_value)

    def select_city(self, city_value):
        """
        客户联系地址选择市
        """
        city_element = Select(self.find_element(self.city_locator))
        city_element.select_by_value(city_value)

    def select_area(self, area_value):
        """
        客户联系地址选择区
        """
        area_element = Select(self.find_element(self.area_locator))
        area_element.select_by_value(area_value)

    def input_street(self, street):
        """
        客户联系地址输入街道
        """
        self.find_element(self.street_locator).send_keys(street)

    def input_first_name(self, first_name):
        """
        首要联系人——输入姓名
        """
        self.find_element(self.first_name_locator).send_keys(first_name)

    def input_salt_name(self, salt_name):
        """
        首要联系人——输入称呼
        """
        self.find_element(self.salt_name_locator).send_keys(salt_name)

    def input_con_email(self, con_email):
        """
        首要联系人——输入邮箱
        """
        self.find_element(self.con_email_locator).send_keys(con_email)

    def input_con_post(self, con_post):
        """
        首要联系人——输入职位
        """
        self.find_element(self.con_post_locator).send_keys(con_post)

    def input_con_qq(self, con_qq):
        """
        首要联系人——输入QQ
        """
        self.find_element(self.con_qq_locator).send_keys(con_qq)

    def input_con_telephone(self, con_telephone):
        """
        首要联系人——输入手机
        """
        self.find_element(self.con_telephone_locator).send_keys(con_telephone)

    def input_con_description(self, con_description):
        """
        首要联系人——输入备注
        """
        self.find_element(self.con_description_locator).send_keys(con_description)

    def select_no_of_employees(self, employees_value):
        """
        选择员工数
        """
        no_of_employees_element = Select(self.find_element(self.no_of_employees_locator))
        no_of_employees_element.select_by_value(employees_value)

    def input_description(self, description):
        """
        输入备注
        """
        self.find_element(self.description_locator).send_keys(description)

    def click_save(self):
        """
        点击保存
        """
        self.find_element(self.save_locator).click()


#返回增删改查后的提示信息
    def get_result_tips(self):
        return self.find_element(self.result_locator).text

#返回弹窗文本信息
    def get_alert_text(self):
        return self.driver.switch_to.alert.text

#返回报错弹窗文本信息
    def get_error_text(self):
        return self.find_element(self.error_locator).text

